package com.push.spider.utils;

import com.push.spider.spider.*;

/**
 * 该爬虫接口只启动一次，即只爬取指定url的页面
 */

public class SpiderUtil {

    public static void ClientSpider(String sourceId, String userSpiderUrl)
    {
        if(!sourceId.trim().isEmpty() && !userSpiderUrl.trim().isEmpty()) {
            System.out.println("执行爬虫任务：" + sourceId);
            HttpClientSpider spider = new HttpClientSpider(sourceId);
            spider.SetSourceSpiderUrlWithUserProvicedUrl(userSpiderUrl);
            long startTime, endTime;
            System.out.println("【爬虫开始ClientSpider】");
            startTime = System.currentTimeMillis();
            spider.run();
            endTime = System.currentTimeMillis();
            System.out.println("【爬虫结束ClientSpider】共抓取篇" + spider.getSize() + "文章，耗时约" + ((endTime - startTime) / 1000) + "秒");
        }else{
            System.out.println("数据源或url为空！");
        }
    }

}
